package memento.fromKanYun;

/**
 * 原始类 ---> 创建、恢复备忘录
 */
public class Original {
    private String state;

    public Original(String state) {
        this.state = state;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    /**
     * 创建备忘录
     * @return
     */
    public Memento createMemento(){
        return new Memento(state);
    }

    /**
     * 恢复备忘录
     * @param memento
     */
    public void recoverMemento(Memento memento){
        this.state = memento.getState();
    }


    /**
     * 由原始类持有备忘录
     */
    private Memento memento;

    public Memento getMemento() {
        return memento;
    }

    public void setMemento(Memento memento) {
        this.memento = memento;
    }
}
